package com.flca.dbs.perst;

import java.util.Map;

import com.flca.frw.dao.DaoFactory;
import com.flca.frw.dao.PersistenceType;
import com.flca.frw.dao.RegisterDatabase;

public class PerstDatabase implements RegisterDatabase {

	private String unitName;
	private PersistenceType type;
	private DaoFactory daoFactory;
	private String username;
	private String password;
	private String url;
	private Class<?> driverClass;
	private Class<?> dialect;
	private String testQuery;
	private Map<String, String> options;

	//--  perst specific properties
	private Class<?> rootClass;
	private int poolsize;
	private boolean mustExist;

	
	/**
	 * This is a helper class to create RegisterDatabase using the Perst database
	 * @param aUnitName
	 * @param url
	 * @param aRootClass
	 * @param aPoolsize
	 * @param aMustExist
	 */
	public PerstDatabase(String aUnitName, String url, Class<?> aRootClass, int aPoolsize, boolean aMustExist) {
		this(aUnitName, url, null, null, aRootClass, aPoolsize, aMustExist);
	}

	/**
	 * 	 * This is a helper class to create RegisterDatabase using the Perst database
	 * @param aUnitName
	 * @param url
	 * @param username
	 * @param password
	 * @param aRootClass
	 * @param aPoolsize
	 * @param aMustExist
	 */
	public PerstDatabase(String aUnitName, String url, String username, String password, Class<?> aRootClass,
			int aPoolsize, boolean aMustExist) {
		super();
		this.type = PersistenceType.PERST;
		this.unitName = aUnitName;
		this.url = url;
		this.username = username;
		this.password = password;
		this.rootClass = aRootClass;
		this.poolsize = aPoolsize;
		this.mustExist = aMustExist;
		this.dialect = null; // not applicable here
	}

	
	public Class<?> getRootClass() {
		return rootClass;
	}

	public void setRootClass(Class<?> rootClass) {
		this.rootClass = rootClass;
	}

	public int getPoolsize() {
		return poolsize;
	}

	public void setPoolsize(int poolsize) {
		this.poolsize = poolsize;
	}

	public boolean isMustExist() {
		return mustExist;
	}

	public void setMustExist(boolean mustExist) {
		this.mustExist = mustExist;
	}

	public Class<?> getStorageRoot() {
		return this.rootClass;
	}

	public long getPerstPoolsize() {
		return this.poolsize;
	}

	public boolean databaseMustExists() {
		return mustExist;
	}

	@Override
	public PersistenceType getPersistenceType() {
		return type;
	}

	@Override
	public String getUnitName() {
		return unitName;
	}

	@Override
	public String getUsername() {
		return username;
	}

	@Override
	public String getPassword() {
		return password;
	}

	@Override
	public Class<?> getDriver() {
		return driverClass;
	}

	@Override
	public String getUrl() {
		return url;
	}

	@Override
	public Map<String, String> getOptions() {
		return options;
	}

	@Override
	public String getTestQuery() {
		return testQuery;
	}

	@Override
	public DaoFactory getDaoFactory() {
		return daoFactory;
	}

	@Override
	public Class<?> getDialect() {
		return dialect;
	}
	
	

}
